<?php
declare(strict_types=1);
namespace app\controller;

use think\facade\Db;
use app\model\Achievements as AchievementsModel;
use app\model\User as UserModel;

class Achievements extends Base
{


    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function achievementsList()
    {
        $post = request()->param();
        $user_model = new AchievementsModel();
        // return $post;
        $res = $user_model->getAll($post['list_rows'], false, ['query' => $post], $post);
        // return $res;
        if ($res[0] !== true) {
            return $this->create($res[1] , '失败', 204);
        }
        // return $res;
        return $this->create($res[1] , '成功');
    }

    public function createDepartment()
    {
        $post = request()->param();
        $user_model = new AchievementsModel();
        $user_model->createDepartment($post['department']);
        return $this->create('', '成功');
    }

    public function deleteDepartment()
    {
        $post = request()->param();
        $user_model = new AchievementsModel();
        $user_model->deleteDepartment($post['id']);
        return $this->create('', '成功');
    }

    public function membersList()
    {
        $post = request()->param();

        $user_model = new AchievementsModel();
        $data = $user_model->getInfoByDepartment($post['department']);
        // return $data[1];
        if ($data[0] === 'false') {
            return $this->create($data[1], '失败', 20001);
        }
        return $this->create($data[1], '成功');
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {

        // table方法必须指定完整的数据表名
        return 'hello';
    }
}